/* 
	changeFormat 修改课程格式
	data  需要修改的数组
	return arr 返回修改完成的数组
*/

const setCourseFormat = (data) => {
	if (data == undefined) return;
	let arr = [];
	data.forEach(e=>{
		try{
			arr.push({
				lable:e.teacher.tag,
				teacher_course_id:e.teacher_course_id,
				teacher_id:e.teacher_id,
				title:(e.grade.hasOwnProperty('title')?e.grade.title:'')+e.language.title+e.teacher.nickname, // 课程名称
				course_count:e.course_count||0, // 已授课次
				hour:e.hour,//单次课程时长
				price:e.price, //价格
				language:e.language.title, //语种
				lanClass:getLangeClass(e.language.title),//语种类名
				year:e.teacher.teaching_year||0, // 教龄
				grade:e.teacher.grade||0, //星级
				score:Number(e.score),//评分
				latitude:e.teacher.latitude, // 
				longitude:e.teacher.longitude,//
				headeravatar:e.teacher.headeravatar,//头像图片
				color:e.language.color
			})
		}catch(err){ //避免出现已经修改过了再次执行的情况
			arr.push(e)
		}
	})
	// console.log(arr)
	// lable: ['复习', '考试'],
	return arr;
}
/* 
	getLangeClass 根据课程名称返回已知的课程类名
	return calss 返回已知的课程类名
*/
const getLangeClass = (name) =>{
		if(!name) return;
		let calss = '';
		switch(name){
			case "韩语":
			calss='korean'
			break;
			case "日语":
			calss='japanese'
			break;
			case "英语":
			calss='english'
			break;
			case "越南语":
			calss='vietnamese'
			break;
			case "阿拉伯语":
			calss='arabic'
			break;
			case "德语":
			calss='german'
			break;
			case "意大利语":
			calss='italian'
			break;
			default:
			calss='text_default'
			break;
		}
		return calss
	}
module.exports = {
	setCourseFormat,
	getLangeClass
}
